/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package course.entities;

import course.ya.doc.from.code.model.ast.StatementTree;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 *
 * @author def
 */
@Entity
@Table(name = "records")
@NamedQueries({
    @NamedQuery(name = "Record.findAll", query = "SELECT r FROM Record r")})
public class Record implements Serializable {

    private static final long serialVersionUID = 34853405603206L;

    @Id
    @Column(name = "record_id")
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @SequenceGenerator(sequenceName = "global_seq", name = "global_seq")
    private long id;

    @OneToOne
    @JoinColumn(name = "tree_id")
    private StatementTree tree;

    @OneToOne
    @JoinColumn(name = "image_id")
    private Image image;

    @ManyToOne
    @JoinColumn(name = "activity_id")
    private UserActivity activity;
    
    public String getName() {
        if(tree.getName().equals(activity.getClassName())) {
            return activity.getClassName() + " <class members>";
        }
        String name = tree.getName();
        return name.substring(name.indexOf(" "));  
    }

    public UserActivity getActivity() {
        return activity;
    }

    public void setActivity(UserActivity activity) {
        this.activity = activity;
    }

    public Record() {
    }

    public StatementTree getTree() {
        return tree;
    }

    public void setTree(StatementTree tree) {
        this.tree = tree;
    }

    public Image getImage() {
        return image;
    }

    public void setImage(Image image) {
        this.image = image;
    }

    public Record(StatementTree tree, Image image) {
        this.tree = tree;
        this.image = image;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

}
